package com.jiaai.util.JPush;


import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.PushPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title JPushThread
 * @since 2017/11/16
 */
public class JPushThread implements Runnable {
    private Logger logger= LoggerFactory.getLogger(JPushThread.class);
    public JPushClient jPushClient;
    public  PushPayload pushPayload;

     /**
     *
     * @param pushPayload 消息体
     */
    public JPushThread(JPushClient jPushClient, PushPayload pushPayload) {
        this.pushPayload = pushPayload;
        this.jPushClient = jPushClient;
    }


    public void run() {
        try {
            PushResult result = jPushClient.sendPush(pushPayload);
            logger.info("Got result - " + result);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            jPushClient.close();
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
    }
}
